package com.qhhc.hospital.controller;

import com.qhhc.hospital.entity.Bed;
import com.qhhc.hospital.service.IBedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BedController {
    @Autowired
    IBedService bedService;

    @RequestMapping("/insertBed")
    public String insertBed(@RequestBody Bed bed){
        bedService.insert(bed);
        return "success";
    }

    @RequestMapping("/getAllBeds")
    public List<Bed> getAllBeds(){
        List<Bed> beds = bedService.selectAll();
        return beds;
    }

    @RequestMapping("/getBed/{bId}")
    public Bed getBedById(@PathVariable("bId") Integer bId){
        return bedService.selectById(bId);
    }
    
    @RequestMapping("/getBedByPatient/{pId}")
    public List<Bed> getBedByPatientId(@PathVariable("pId") Integer pId){
        return bedService.selectByPatientId(pId);
    }
    
    @RequestMapping("/getBedByDoctor/{dId}")
    public List<Bed> getBedByDoctorId(@PathVariable("dId") Integer dId){
        return bedService.selectByDoctorId(dId);
    }

    @RequestMapping("/updateBed")
    public String updateBed(@RequestBody Bed bed){
        bedService.update(bed);
        return "success";
    }

    @RequestMapping("/deleteBed/{bId}")
    public String deleteBed(@PathVariable("bId") Integer bId){
        bedService.delete(bId);
        return "success";
    }
} 